<template>
  <div class="app-container">
    <!-- 查询表单 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
          range-separator="-" start-placeholder="开始日期时间" end-placeholder="结束日期时间">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="warning" plain icon="Download" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格展示 -->
    <el-table v-loading="loading" :data="guozhongList">
      <el-table-column label="供货单位" align="center">
        <template slot-scope="">
          <span>自然人</span>
        </template>
      </el-table-column>
      <el-table-column label="总过磅车数" align="center" :prop="'total'" />
      <el-table-column label="未登车数" align="center" :prop="'fpshrNullCount'" />
      <el-table-column label="已登车数" align="center" :prop="'fpshrNotNullCount'" />
      <el-table-column label="过磅净重" align="center" :prop="'totalJz'" />
      <el-table-column label="登记净重" align="center" :prop="'djjz'" />
      <el-table-column label="未登记净重" align="center" :prop="'wdjjz'" />
      <el-table-column label="过磅金额" align="center" :prop="'totalJje'" />
      <el-table-column label="登记金额" align="center" :prop="'djje'" />
      <el-table-column label="未登记金额" align="center" :prop="'wdjje'" />
    </el-table>

    <!-- 分页 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listGuozhong } from "@/api/system/Fdongbei/fapiao";

export default {
  name: "Guozhong",
  data() {
    const today = new Date();
    const twoWeeksAgo = new Date(today);
    twoWeeksAgo.setDate(today.getDate() - 14);
    const formatDate = (date) => {
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, '0');
      const day = String(date.getDate()).padStart(2, '0');
      return `${year}-${month}-${day} 00:00:00`;
    };
    return {
      loading: true,
      showSearch: true,
      total: 0,
      // 日期范围
      dateRange: [formatDate(twoWeeksAgo), formatDate(today)],
      guozhongList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取列表数据
    getList() {
      this.loading = true;
      listGuozhong(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.guozhongList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 搜索按钮操作
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    // 导出按钮操作
    handleExport() {
      this.download('system/fapiao/export', {
        ...this.queryParams
      }, `guozhong_${new Date().getTime()}.xlsx`)
    },

    // 重置按钮操作
    resetQuery() {
      this.dateRange = []; // 重置时间范围
      this.getList(); // 刷新数据
    }

  }
};
</script>
